package com.example.blogspring.service;

import com.example.blogspring.mapper.BlogMapper;
import com.example.blogspring.model.BlogInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * @author : niu niu
 * @version : 1.0.0
 * @date : 2023/5/22 18:01
 */
@Service
public class BlogService  {
    @Autowired
    private BlogMapper blogMapper;

    public List<BlogInfo> getBlogList(){
        return blogMapper.getBlogList();
    }

    public BlogInfo getBlogById(Integer id){
        return blogMapper.getBlogById(id);
    }
    public Integer add(BlogInfo blogInfo){
        return blogMapper.add(blogInfo);
    }
    public Integer delete(Integer id){
        return blogMapper.delete(id);
    }
    public Integer update(BlogInfo blogInfo){
        return blogMapper.update(blogInfo);
    }

    public Integer getCount(){
        return blogMapper.getCount();
    }

    public List<BlogInfo> getListByPage(Integer psize,Integer offsize){
        List<BlogInfo> listByPage = blogMapper.getListByPage(psize, offsize);
        for (int i =0;i<listByPage.size();i++){
            if ( listByPage.get(i).getContent().length()>100){
                listByPage.get(i).setContent(listByPage.get(i).getContent().substring(0,100)+"......");
            }
        }
        return listByPage;
    }
}
